package org.balthie.cal.impl.cmd;

import java.util.Deque;

import org.balthie.cal.core.AbsCommand;
import org.balthie.cal.core.ICommand;
import org.balthie.cal.core.IMathOperator;
import org.balthie.cal.impl.cmd.spec.ContainsCmdKindSpecs;
import org.balthie.cal.impl.cmd.spec.PrevCmdTypeSpecs;

public class GenericMathOptCmd extends AbsCommand implements IMathOperator {

	private MathOperatorType type;

	public GenericMathOptCmd(MathOperatorType type) {
		super(type.getLiterally());
		this.type = type;
		// 运算符前只能是数字, 一个算式不能有多个运算符
		this.legalSpecs = PrevCmdTypeSpecs.IS_NUMB.not(ContainsCmdKindSpecs.CONTAINS_MATHOPT);
	}

	@Override
	public boolean isCompleted(Deque<ICommand> deque) {
		// 输入运算符，默认视算式未结束
		return Boolean.FALSE;
	}

	@Override
	public MathOperatorType getOperator() {
		return this.type;
	}

	@Override
	public String toString() {
		return String.format("MathOptCmd [type=%s, getOperator()=%s, getLiterally()=%s]", type, getOperator(),
				getLiterally());
	}

	@Override
	public String getTips() {
		return this.getLiterally();
	}
}
